package tds.model27;

import java.util.HashMap;
import java.util.Map;

/**
 * @Company 杭州先锋电子技术股份有限公司
 * @ClassName ChessFlyWeightFactory
 * @Description 享元工厂，棋子工厂
 * @author tds
 * @Date 2020/2/8 16:07
 * @version 1.0.0
 */
public class ChessFlyWeightFactory {

    private static Map<String, ChessFlyWeight> chessFlyWeightMap = new HashMap<>();

    /**
     * @Description 获取一个棋子对象
     * @param color
     * @return tds.model27.ChessFlyWeight
     */
    public static ChessFlyWeight getChess(String color){
        ChessFlyWeight chessFlyWeight = chessFlyWeightMap.get(color);
        if(chessFlyWeight == null){
            chessFlyWeight = new ConcreteChess(color);
            chessFlyWeightMap.put(color, chessFlyWeight);
        }
        return chessFlyWeight;
    }
}
